<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML>
<%@include file="/common/taglibs.jsp" %>
<%@include file="/common/javascript.jsp" %>
<html>
	<head>
	<meta charset="utf-8">
  	<script type="text/javascript">
		
		$(function(){
			var typeid=UrlParm.parm("typeid"); 
			//加载数据
			$("#dg").datagrid({url:'policyGrid?typeid='+typeid,rownumbers:true,singleSelect:false,selectOnCheck:true,
					fitColumns:true,pagination:true,loadMsg:'数据加载中...',pageSize:10,
					frozenColumns:[[     
                  		{field:'ck',checkbox:true}
            		]],
					columns:[[  
						{field:'id',title:"序号",width:50,align:'center',hidden:true}, 
						{field:'num',title:"编号",width:50,align:'center'}, 
						{field:'name',title:"标题",width:150},
						{field:'content',title:"内容",width:200},
						{field:'remark',title:"备注",width:120,align:'center'}
					]]  
				});
			
			$("#dg").datagrid('getPager').pagination({//分页栏下方文字显示
				showPageList:false,
				beforePageText:'第',
				afterPageText: '页    共 {pages} 页',            
			    displayMsg:'当前显示   从第{from}条到{to}条     共{total}条记录'
			});
			
			$("#btnAdd").bind('click',function(){
				pageLoading(window.frames["myFrame"].document);
				$("#myFrame")[0].src='policyAction_toForm?viewType=add';
				$("#content").dialog({ title:'增加', width:550, height:410, closed:true, 
					minimizable:true, maximizable:true, modal:true,resizable:true,
					buttons:[{
						text:'保存',
						  handler:function(){
							  myFrame.window.saveInfo();
						  }
					  },{
						  text:'关闭',
						  handler:function(){
							  closeContent();
						  }
					  }]
				});
				$("#content").dialog('open');
			});
			
			$("#btnEdit").bind('click',function(){
				var rows=$("#dg").datagrid('getSelections');
				if(rows && rows.length>1){
					window.parent.window.$.messager.alert('提示','请选择单一数据项修改',"info");
				}else{
					var row =$("#dg").datagrid('getSelected');
					if(row){
						pageLoading(window.frames["myFrame"].document);
						$("#myFrame")[0].src='policyAction_toForm?viewType=modify&model.id='+row.id;
						$("#content").dialog({ title:'修改', width:550, height:410, closed:true, 
							minimizable:true, maximizable:true,modal:true,resizable:true,
							buttons:[{
								text:'保存',
								  handler:function(){
									  myFrame.window.saveInfo();
								  }
							  },{
								  text:'关闭',
								  handler:function(){
									  $("#content").dialog('close');
								  }
							  }]
						});
						$("#content").dialog('open');
					}else{
						window.parent.window.$.messager.alert('提示','请先选择要修改的数据项',"info");
					}	
				}
			});
			$("#btnDetail").bind('click',function(){
				var rows=$("#dg").datagrid('getSelections');
				if(rows && rows.length>1){
					window.parent.window.$.messager.alert('提示','请选择一项政策',"info");
				}else{
					var row =$("#dg").datagrid('getSelected');
					if(row){
						pageLoading(window.frames["myFrame"].document);
						$("#myFrame")[0].src='policyAction_toForm?viewType=detail&model.id='+row.id;
						$("#content").dialog({ title:'查看', width:550, height:410, closed:true, 
							minimizable:true, maximizable:true,modal:true,resizable:true,
							buttons:[{
								  text:'关闭',
								  handler:function(){
									  $("#content").dialog('close');
								  }
							  }]
						});
						$("#content").dialog('open');
					}else{
						window.parent.window.$.messager.alert('提示','请先选择要查看的政策',"info");
					}	
				}
			});
			
			$("#btnDelete").bind('click',function(){
				var rows=$("#dg").datagrid('getSelections');
				if(rows!=null && rows.length>0){
					window.parent.window.$.messager.confirm('提示','确定要删除吗？',function(r){
						if (r){  
							var ids="";
							for(var i=0;i<rows.length;i++){
								ids+=rows[i].id+",";
							}
							$.post("policyAction_delete",{ids:ids},function(data){
								var data = eval('(' + data + ')');
								if (!data.success){ //删除失败  
									window.parent.window.$.messager.alert('提示',"错误"+data.message,"info");
        						}else{//删除成功
        							window.parent.window.$.messager.alert('提示',data.message,"info",function(){
        								$('#dg').datagrid('reload'); //刷新网格
        							});
        						} 
							});
						}
					});
				}else{
					window.parent.window.$.messager.alert('提示','请先选择要删除的数据项',"info");
				}
			});
			
			$("#btnSearch").bind('click',function(){
				if(!isNull('start')) return; //验证日期是否为空
				if(!isNull('end')) return; //验证日期是否为空
				if(!checkdate('start','end')) return;
				$('#dg').datagrid('load',{
					viewType:'query',startDate:$("#start").val(),endDate:$("#end").val()
				});
			});
			
		});
		
		function closeContent(){
			$("#content").dialog('close');
			$('#dg').datagrid('reload');
		}
		
	</script>
  	</head>
  
  	<body  style="margin:0px; padding:0px;overflow-style:clear;" >
	<div data-options="region:'north',border:false" style="height:40px;padding:0px;margin:0px;" id="mainsearch">
    	<div id="formsearch" style="padding:10px;">
            	开始时间：<input id="start" name="start" type="text" class="Wdate" onclick="WdatePicker({skin:'whyGreen'})"
                			value='<s:date name="model.dateCre" format="yyyy-MM-dd"/>'  />
                                                结束时间：<input id="end" name="end" type="text" class="Wdate" onclick="WdatePicker({skin:'whyGreen'})"
                			value='<s:date name="model.dateCre" format="yyyy-MM-dd"/>'  />
            	<a id="btnSearch"  class="easyui-linkbutton" data-options="iconCls:'icon-search'">查询</a>
        </div>
    </div>
    <div id="toolbar" style="background:#C9DFFF" >
   	 	<c:if test="${permissionId==1}">
   	 		<a id="btnAdd"  class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:'true'" style="text-align:center">增加</a>
        	<a id="btnEdit" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:'true'" style="text-align:center">修改</a>
        	<a id="btnDelete" class="easyui-linkbutton" data-options="iconCls:'icon-delete',plain:'true'" style="text-align:center">删除</a>
   	 	</c:if>
    	<a id="btnDetail" class="easyui-linkbutton" data-options="iconCls:'icon-detail',plain:'true'" style="text-align:center">详情</a>
    </div>
    <table id="dg"> </table>
    <div id="content">
    	<iframe id="myFrame" name="myFrame" frameborder="0" scrolling="no"  src="" style="width:100%;height:95%;"></iframe> 
    </div> 
</body>
</html>
